﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoCooker3
{
    class Program
    {
        static void Main(string[] args)
        {
            AutoCooker3 easyCooker = new AutoCooker3();
            
            //Mother mother = new Mother();
            //Son son = new Son();
            //easyCooker.started = new CookStartedReply(mother.CookStartedReply);
            //easyCooker.completed = new CookCompletedReply(son.CookCompletedReply);
              
            // use static method 
            easyCooker.started = new CookStartedReply(Mother.CookStartedReply);
            easyCooker.completed = new CookCompletedReply(Son.CookCompletedReply);

            easyCooker.DoCook();

            // 客户端可以随意添加委托，激发事件。 
            // 如果错误用 "=" 而不是 "+=", 新添加的委托会替换掉原来的委托链
            // 解决方案： event  (see “AutoCooker4”)
            // enent关键字在委托的外边包装了一个 property，仅让 C#客户通过 += 和 -=操作符来添加和移除，不能直接激发事件。
            AutoCooker3 anothereasyCooker = new AutoCooker3();
            anothereasyCooker.started += new CookStartedReply(Mother.CookStartedReply);
            anothereasyCooker.completed += new CookCompletedReply(Mother.CookCompletedReply);
            anothereasyCooker.completed = new CookCompletedReply(Son.CookCompletedReply); // 会替换掉Mother.CookCompleted
            anothereasyCooker.DoCook();
            anothereasyCooker.completed();

            Console.ReadLine();
        }
    }
}
